<template>
	<view class="p15">
		<uni-section title="个人介绍" type="line"></uni-section>
		<uni-forms class="form" ref="form" :modelValue="form" label-position="left" label-width="80px">
			<uni-forms-item label="照片">
				<view class="text-center">
					<uni-file-picker limit="1" :del-icon="false" disable-preview file-mediatype="image" @select="onAvatar">
						<image :src="form.head_img" mode="widthFix" />
					</uni-file-picker>
				</view>
			</uni-forms-item>
			<uni-forms-item label="姓名" required>
				<uni-easyinput v-model="form.name" placeholder="请输入姓名" />
			</uni-forms-item>
			<uni-forms-item label="性别" required>
				<uni-data-checkbox v-model="form.sex" :localdata="sex" />
			</uni-forms-item>
			<uni-forms-item label="出生日期" required>
				<uni-datetime-picker type="date" placeholder="请输入出生日期" :clear-icon="false" v-model="form.birthday"/>
			</uni-forms-item>
			<uni-forms-item label="工作日期" required>
				<uni-datetime-picker type="date" placeholder="请输入工作日期" :clear-icon="false" v-model="form.workyear"/>
			</uni-forms-item>
			<uni-forms-item label="电话" required>
				<uni-easyinput v-model="form.mobilephone" placeholder="请输入电话" />
			</uni-forms-item>
			<uni-forms-item label="学历" required>
				<uni-data-select v-model="form.education" :localdata="educations" placeholder="请选择学历"></uni-data-select>
			</uni-forms-item>
			<uni-forms-item label="求职状态" required>
				<uni-data-select v-model="form.current_situation" :localdata="job_hunt" placeholder="请选择求职状态"></uni-data-select>
			</uni-forms-item>
			<uni-forms-item label="邮箱" required>
				<uni-easyinput v-model="form.email" placeholder="请输入邮箱" />
			</uni-forms-item>
			<uni-forms-item label="居住地" required>
				<uni-easyinput v-model="form.area" placeholder="请输入居住地" />
			</uni-forms-item>
			<uni-forms-item label="应届生">
				<uni-data-checkbox v-model="form.identity" :localdata="identitys" />
			</uni-forms-item>
			<uni-forms-item label="毕业院校">
				<uni-easyinput v-model="form.school" placeholder="请输入毕业院校" />
			</uni-forms-item>
		</uni-forms>
		<button class="default-button" @click="save()">提交</button>
	</view>
</template>

<script>
	export default {
		name:"resume_userinfo",
		data() {
			return {
				id:0,
				form:{},
				educations:[],
				job_hunt:[],
				identitys:[{text:'是',value:1},{text:'否',value:0}],
				sex:[{text:'男',value:1},{text:'女',value:0}]
			};
		},
		onLoad(options) {
			this.id = options.id
			this.educations = this.$func.map_arr(this.$func.edu)
			this.job_hunt = this.$func.map_arr(this.$func.job_hunt)
			this.onGetData()
		},
		methods: {
			onGetData(){
				let _this = this
				this.$request('/api/getBasicInfo','POST',{resume_id:_this.resume_id}).then(res => {
					_this.form = res.data ? res.data : {}
				}).catch(err => {
					console.log(err)
				})
			},
			save(){
				if(!this.form.name){
					uni.showToast({title: '请输入姓名',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.birthday){
					uni.showToast({title: '请输入出生日期',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.workyear){
					uni.showToast({title: '请输入工作日期',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.mobilephone){
					uni.showToast({title: '请输入电话',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.education){
					uni.showToast({title: '请输入学历',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.current_situation){
					uni.showToast({title: '请选择求职状态',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.email){
					uni.showToast({title: '请输入Email',icon: 'error',duration: 2000})
					return;
				}
				if(!this.form.area){
					uni.showToast({title: '请输入居住地',icon: 'error',duration: 2000})
					return;
				}
				if(this.id == 0){
					delete this.form.id
				}
				let _this = this
				this.$request('/api/saveBasicInfo','POST',this.form).then(res => {
					if(res.code != 0){
						uni.showToast({title: '保存失败',icon: 'error',duration: 2000})
						return;
					}
					
					uni.showToast({title: '保存成功',icon: 'success',duration: 2000})
					uni.navigateTo({
						url: "/user/resume/resume"
					});
				}).catch(err => {
					console.log(err)
				})
			},
			onUploadOneImg(e){
				let _this = this
				this.$request_api('applet_api/WxAppOneLoad','POST',{fileurl:e}).then(res => {
					_this.form.head_img = res.data
				}).catch(err => {
					console.log(err)
				})
			},
			onAvatar(e){
				let _this = this
				_this.imgToBase64(e.tempFilePaths[0],'avatar')
			},
			imgToBase64(imagePath,type) {
				let _this = this
				const fileSystemManager = uni.getFileSystemManager();
				fileSystemManager.readFile({
					filePath: imagePath,
					encoding: 'base64',
					success: res => {
						let fileurl = res.data
						_this.onUploadOneImg(fileurl)
						return;
					},
					fail: err => {
						callback(null);
					}
				});
			}
		}
	}
</script>

<style>

</style>